<template>
  <view class="details">
    <view class="ThreeXQ">
      <view style="height:92vh;overflow-y: auto">
        <view class="" v-for="(item, index) in QY" :key="index">
          <u-cell size="large" :title="item.lable" :value="item.lable=='统一信用代码'?plusXing(modle1[item.key]):modle1[item.key]"></u-cell>
        </view>
        <view class="backgrounds"> </view>
        <view class="tabs">
          <van-tabs :value="active" color="dodgerblue" line-width="80px" background="#eee"
            title-active-color="dodgerblue" line-height="4px" @click="handlegoto">
            <van-tab title="企业资质">
              <view class="" v-for="(item, index) in QY1" :key="index">
                <span v-if="item.title">{{modle1[item.key]}}</span>
                <u-cell size="large" required :title="item.lable" :value="modle1[item.key]?modle1[item.key]:'暂无数据'" v-else></u-cell>
              </view>
            </van-tab>
            <van-tab title="注册成员">
              <view v-if="ISshow">
                <u-collapse accordion>
                  <u-collapse-item v-for="(item, index) in ZCRY" :key="index" :title="item.ryxm">
                    <u-cell size="large" v-for="(item1, index1) in QY2" :key="index1" required :title="item1.lable"
                      :value="ZCRY[index][item1.key]||'暂无数据'"></u-cell>
                  </u-collapse-item>
                </u-collapse>
              </view>
            </van-tab>
            <van-tab title="诚信信息">
              <u-collapse accordion>
                <u-collapse-item v-for="(item, index) in CXXX" :key="index" :title="item.lb">
                  <u-cell size="large" v-for="(item1, index1) in QY3" :key="index1" required :title="item1.lable"
                    :value="CXXX[index][item1.key]||'暂无数据'"></u-cell>
                </u-collapse-item>
              </u-collapse>
            </van-tab>
          </van-tabs>
        </view>
      </view>
      <u-button v-if="showIS" @click="handleGotonext1" style="width: 100%; position: absolute; bottom: 0.5rem" text="确定"
        size="large" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"></u-button>
    </view>
    <view>
      <u-toast ref="uToast"></u-toast>
    </view>
  </view>
</template>


<script>
import {
  getDatalistForTree,
  ECAOpenDataView,
  ECAinsertDataView,
  ECAFileServerUpload,
  ECAPrepareCreateProcess,
  ECAPrepareLoadWorkflowScript,
  ECAPrepareLoadCreateProcess,
  ECAPlatSendTask,
  ECAExecProcedure,
  getServiceData,
  existHouseBaseInfo
} from "@/common/utils/api.js";
export default {
  data() {
    return {
      active: ["0"],
      options: "",
      ISshow: false,
      uuid: "",
      showIS: true,
      modle1: {
        qymc: "",
        tyshxydm: "",
        frdb: "",
        areaname: "",
        fzrq: "",
        qybj: "",
        fzyxq: "",
        fzjg: "",
        zzzsbh: "",
        zzdj: "",
        zzlb: ''
      },
      ZCRY: [
      ],
      CXXX: [
      ],
      QY: [
        {
          lable: "企业名称",
          key: "qymc",
          name: null,
        },
        {
          lable: "统一信用代码",
          key: "tyshxydm",
          name: "浙江政欣工程设计有限公司",
        },
        {
          lable: "法人代表",
          key: "frdb",
          name: "***",
        },

        {
          lable: "注册区域",
          key: "areaname",
          name: "临安区",
        },
        {
          lable: "通讯地址",
          key: "areaname",
          name: "浙江省杭州市临安区",
        },
        {
          lable: "发证日期",
          key: "fzrq",
          name: "浙江省杭州市临安区",
        },
        {
          lable: "发证有效期",
          key: "fzyxq",
          name: "浙江省杭州市临安区",
        },
        {
          lable: "企业报价",
          key: "qybj",
          name: "浙江省杭州市临安区",
        }
      ],
      QY1: [
        {
          lable: "资质类别",
          key: "zzlb",
        },
        {
          lable: "资质等级",
          key: "zzdj",
        },
        {
          lable: "资质证书编号",
          key: "zzzsbh",
        },
        {
          lable: "发证日期",
          key: "fzrq",
        },
        {
          lable: "证书有效期",
          key: "fzyxq",
        },
        {
          lable: "发证机关",
          key: "fzjg",
        },
      ],
      QY2: [
        {
          lable: "注册类型及等级",
          key: "zclxjdj",
        },
        {
          lable: "注册证书及编号",
          key: "zczsbh",
        },
        {
          lable: "发证日期",
          key: "fzrq",
        },
        {
          lable: "发证机关",
          key: "fzjg",
        },
        {
          lable: "有效期至",
          key: "fzyxq",
        },
        {
          lable: "专业",
          key: "zy",
        },
        {
          lable: "学历",
          key: "xl",
        },
        {
          lable: "是否现场人员",
          key: "sfxcry",
        },
        {
          lable: "是否注册人员",
          key: "sfzcry",
        },
      ],
      QY3: [
        {
          lable: "类别",
          key: "lb",
        },
        {
          lable: "发布有效期至",
          key: "fzjg",
        },
        {
          lable: "实施部门",
          key: "ssbm",
        },
        {
          lable: "文号",
          key: "wh",
        },
        {
          lable: "行为描述",
          key: "xwms",
        },
        {
          lable: "决定内容",
          key: "jdnr",
        },
      ]
    };
  },
  methods: {
    handlegoto(e) {
      if (e.detail.title == "注册成员") {
        this.ISshow = true
        console.log(this.ISshow)
      } else {
        this.ISshow = false
      }
    },
    plusXing(str, frontLen, endLen) {
      //浙里办新规则
      if (str.length < 9) {
        return '*' + str.substring(1, str.length) //截取name 字符串截取第一个字符
      } else if (str.length > 9 && str.length < 18) {
        return str.substring(0, 3) + '****' + str.substring(7, str.length) //截取第一个和大于第4个字符
      } else {
        return str.substring(0, 1) + '****************' + str.substring(str.length - 1, str.length)
      }
    },
    showToast3(params) {
      this.$refs.uToast.show({
        message: "更新失败",
        type: "error",
      });
    },
    async getDataD(data) {
      let daat2 = {
        "params": { "filing_id": data },
        "serviceOrder": 2
      }
      const res = await getServiceData(daat2);
      console.log(JSON.parse(res.data.desc))
      let it = JSON.parse(res.data.desc)
      this.modle1 = it[0].qyzz[0]
      this.ZCRY = it[0].zcry
      this.CXXX = it[0].cxxx
    },
    showToast1(params) {
      this.$refs.uToast.show({
        message: "更新成功",
        type: "success",
      });
    },
    guid() {
      return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
        /[xy]/g,
        function (c) {
          var r = (Math.random() * 16) | 0,
            v = c == "x" ? r : (r & 0x3) | 0x8;
          return v.toString(16);
        }
      );
    },
    async handleGotonext1() {
      if (uni.getStorageSync('reload')) {
        let time = Date.now();
        this.uuid = this.guid();
        let dat = JSON.parse(uni.getStorageSync('reload'))
        let data3 = {
          procName: "update_jdjg_by_pkid",
          dtParams: JSON.stringify([
            {
              "i_pkid": dat.PKID,
              "i_jdjgmc": "浙江政欣工程设计有限公司",
              "i_tyshxydm": "913301857471537181",
              "i_wtsy": dat.WTSY
            },
          ]),
        };
        const user = await ECAExecProcedure(data3);
        if (user.Data.length > 0) {
          //先创建流程
          let data1 = {
            wfGuid: "{48A968B4-A044-4115-A9DB-099029B2E011}",
            //生成一个uuid
            entityRowGuid: dat.ROW_GUID,
            time: time,
            viewParameter: {},
          };
          const res1 = await ECAPrepareCreateProcess(data1);
          //调用ECAPrepareLoadWorkflowScript
          const res2 = await ECAPrepareLoadWorkflowScript(
            "-1",
            time,
            "{48A968B4-A044-4115-A9DB-099029B2E011}"
          );
          let formdata1 = {
            matterGuid: "",
            wfGuid: "{48A968B4-A044-4115-A9DB-099029B2E011}",
            bizGuid: "ec2ac527-d791-48b6-9f14-6d901f6a8e30",
            entityRowGuid: dat.ROW_GUID,
            time: time,
            viewParameter: {},
          };
          const res3 = await ECAPrepareLoadCreateProcess(formdata1);
          const res4 = await ECAPrepareLoadWorkflowScript(
            dat.TASK_ID,
            time,
            "{48A968B4-A044-4115-A9DB-099029B2E011}"
          );
          //获取下一个环节的人员\
          let data3 = {
            procName: "get_user_by_taskId",
            dtParams: JSON.stringify([{
              "i_taskId": dat.TASK_ID,
              "i_type": 1
            }]),
          }
          const user = await ECAExecProcedure(data3)
          console.log(user)
          let data2 = {
            taskId: dat.TASK_ID,
            direction: 0,
            wfBoxGuid: "ec2ac527-d791-48b6-9f14-6d901f6a8e30",
            actionText: "",
            taskName: "",
            wfGuid: "{48A968B4-A044-4115-A9DB-099029B2E011}",
            sendNodes: JSON.stringify([
              {
                TNID: 124,
                PTNID: 1,
                TEXT: user.Data[0]._USERNAME,
                WFNODEGUID: "{FA54F190-31A8-41A1-9CA8-798339A5FC68}",
                WFNODETYPE: 2,
                WFNODENAME: "鉴定机构",
                ISUSER: 1,
                USERID: user.Data[0]._USERID,
                USERNAME: user.Data[0]._USERNAME,
                SINGLEASSIGN: true,
                PREJUNCNODEGUID: "",
                SORTNUM: 0,
                selected: true,
              },
            ]),
            time,
          };
          //拿到takid
          const res5 = await ECAPlatSendTask(data2);
          if (res5.Success) {
            this.showToast1();
            setTimeout(() => {
              this.$nextTick(() => {
                uni.navigateTo({
                  url: "/",
                  animationType: "fade-in",
                });
              });
            }, 1000);
          } else {
            this.showToast3();
          }
        }
        //成功之后清除reload的内容
        uni.setStorageSync('reload', '')
      } else {
        uni.setStorageSync('JDGS',this.modle1)
        if (this.options.component) {
          uni.navigateTo({
            url: "/pages/Commissioned/Commissioned",
          });
        } else {
          uni.navigateTo({
            url: "/pages/applyAppraisal/applyAppraisal",
          });
        }
        setTimeout(() => {
          uni.$emit("details", this.QY);
        }, 500);
      }
    },
  },
  created() {
    this.ISshow = false
    let itemData = uni.getStorageSync('itemData')
    this.getDataD(itemData.filing_id)
  },
  onLoad(options) {
    this.options = options;
    console.log(this.options)
    // if(this.options.component == undefined || uni.getStorageSync('reload') == ''){
    //   this.showIS = false
    // } else{
    //   this.showIS =  true
    // }
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        title: "详情信息",
      })
        .then((res) => { })
        .catch((err) => { });
    }
  },
};
</script>


<style lang="scss" scoped>
.details {
  height: 100vh;
  overflow-y: auto;

  .ThreeXQ .backgrounds {
    height: 1rem;
    background: #eee;
  }

  .ThreeXQ {
    // height: 100vh;
    overflow-y: auto;

    .tabs {
      margin: 0 auto;
    }
  }
}
</style>